package io.renren.modules.business.controller;

import java.util.List;
import java.util.Map;

import io.renren.modules.business.entity.BusInfoEntity;
import io.renren.modules.business.service.BusInfoService;
import io.renren.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import javax.servlet.http.HttpServletRequest;


/**
 * 信息管理
 *
 * @author liao mengqing
 */
@RestController
@RequestMapping("business/info")
public class BusInfoController extends AbstractController {
    @Autowired
    private BusInfoService busInfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("business:info:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = null;
        String key = (String) params.get("key");
        if (key.length() != 0 && !"".equals(key)) {
            page = busInfoService.queryKey(params);
        }else {
            page = busInfoService.queryPage(params);
        }
        return R.ok().put("page", page);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("business:info:save")
    public R save(@RequestBody BusInfoEntity busInfoEntity, HttpServletRequest request){
        busInfoEntity.setPublisherId(getUserId());
        busInfoService.saveInfo(busInfoEntity);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("business:info:delete")
    public R delete(@RequestBody Long[] infoIds){
		busInfoService.deleteInfo(infoIds);
        return R.ok();
    }

    /**
     * 获取微信小程序首页轮播图内容
     * @return
     */
    @PostMapping("/swiper")
    public R swiper() {
        System.out.println("获取微信小程序首页轮播图内容");
        List<Map<String, Object>> article = busInfoService.indexSwiper();
        return R.ok().put("article" , article);
    }
}
